package org.kzwl.book.controller.web;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.kzwl.service.app.impl.MinIoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;

@Api("图片服务")
@RestController
@RequestMapping("/me-minio")
public class MioController {

    @Autowired
    MinIoService minIoService;

    @ApiOperation(value = "图片上传")
    @PostMapping("/uploadImages")
    public String uploadImages(@RequestParam("file")MultipartFile file)
    {
        return minIoService.upload(file);
    }


    @ApiOperation(value = "富文本图片上传")
    @PostMapping("/uploadEditor")
    public Map<String,Object> uploadEditor(@RequestParam("file")MultipartFile file)
    {
        Map<String,Object> objectMap = new HashMap<>();
        String upload = minIoService.upload(file);
        objectMap.put("errno",0);
        objectMap.put("data", Collections.singletonList(upload));
        return objectMap;
    }


}
